/**
 * Copyright &copy; 2016-2017 <a href="http://www.smartfactorycloud.cn">SmartFactory</a> All rights reserved.
 */
package com.wfy.common.persistence;

import com.alibaba.fastjson.annotation.JSONField;
import com.wfy.common.util.IdGen;
import com.wfy.modules.sys.entity.User;

import java.util.Date;

/**
 * 数据Entity类
 *
 * @author SmartFactory
 * @version 2014-05-16
 */
public abstract class DataEntity<T> extends BaseEntity<T> {

    private static final long serialVersionUID = 1L;

    @JSONField(serialize = false)
    protected transient String token;

    @JSONField(serialize = false)
    protected String remarks;    // 备注
    @JSONField(serialize = false)
    protected User createBy;    // 创建者
    @JSONField(serialize = false)
    protected Date createDate;    // 创建日期
    @JSONField(serialize = false)
    protected User updateBy;    // 更新者
    @JSONField(serialize = false)
    protected Date updateDate;    // 更新日期
    @JSONField(serialize = false)
    protected String delFlag;    // 删除标记（0：正常；1：删除；2：审核）

    public DataEntity() {
        super();
        this.delFlag = DEL_FLAG_NORMAL;
    }

    public DataEntity(String id) {
        super(id);
    }

    /**
     * 插入之前执行方法，需要手动调用
     */
    @Override
    public void preInsert() {
        // 不限制ID为UUID，调用setIsNewRecord()使用自定义ID
        if (!this.isNewRecord) {
            setId(IdGen.uuid());
        }

        // 无用户
        this.updateBy = null;
        this.createBy = null;
        this.updateDate = new Date();
        this.createDate = this.updateDate;
    }

    /**
     * 更新之前执行方法，需要手动调用
     */
    @Override
    public void preUpdate() {
        this.updateBy = null;
        this.updateDate = new Date();
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    @JSONField(serialize = false)
    public User getCreateBy() {
        return createBy;
    }

    public void setCreateBy(User createBy) {
        this.createBy = createBy;
    }

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @JSONField(serialize = false)
    public User getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(User updateBy) {
        this.updateBy = updateBy;
    }

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    @JSONField(serialize = false)
    public String getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(String delFlag) {
        this.delFlag = delFlag;
    }

}
